@include('admin.header')
<style>
form{
	margin-left: 20px;

}
label{
	line-height:40px;
}
label span{
	display: inline-block;
}
input[type="submit"]{
	position: absolute;
	right: 20px;
	bottom: 20px;
	margin-left: 20px;
	display: inline-block;
	text-align: right;
}




</style>
<meta charset="UTF-8"/>
</head>
<body>
	<div class="wrap js-check-wrap">

		<form  method="post" class="js-ajax-tree js-category-add">
			<div>
			   <label>
				<span>账户权限：</span>
				 <div class="soon"><input type="checkbox" value="0" name="rules[] " class="is_ok" @if(isset($statusArr) && $statusArr[0]==0){echo checked='checked'; } @endif/>全部容许</div>
				 <div class="soon"><input type="checkbox" value="1" name="rules[]" class="rule-son" @if(isset($statusArr) && $statusArr[0]==1){echo checked='checked'; } @endif />禁止进账</div>
				 <div class="soon"><input type="checkbox" value="2" name="rules[]" class="rule-son" @if(isset($statusArr) && $statusArr[0]==2){echo checked='checked'; } @endif />禁止出账</div>
				 <div class="soon"><input type="checkbox" value="4" name="rules[]" class="rule-son" @if(isset($statusArr) && $statusArr[0]==4){echo checked='checked'; } @endif />禁止冻结</div>
				 <div class="soon"><input type="checkbox" value="8" name="rules[]" class="rule-son" @if(isset($statusArr) && $statusArr[0]==8){echo checked='checked'; } @endif />禁止解冻</div>
				 <div class="soon"><input type="checkbox" value="-1" name="rules[]" class="rule-parent rule-son" @if(isset($statusArr[4]) && $statusArr[4]==-1){echo checked='checked'; } @endif />全部禁止</div>
				</label>

				<label>
				<span>备注：</span>
				<input type="text" style="width: 200px;height: 35px;" name="remarks" value="{{$data->remarks or ''}}"/>
				
				</label>
				<input type="hidden" name="purseid" value="{{$purseid or ''}}"/>
				<input type="submit" class="btn btn-primary" value="提交" />
				
			</div>
		</form>
	</div>
	<script type="text/javascript" src="/static/js/common.js"></script>
	<script type="text/javascript" src="/static/js/validate/validate.js"></script>
	<script type="text/javascript" src="/static/js/layer/layer.js"></script>
	<script type="text/javascript">
			$(function() {

			  $('.rule-parent').bind('click',function(){
		        if($(this).is(':checked')){
		            $(this).parent().siblings('.soon').children('.rule-son').prop('checked',true);
		            $(this).parent().siblings('.soon').children('.is_ok').prop('checked',false);
		        }else{
		            $(this).parent().siblings('.soon').children('.rule-son').prop('checked',false);
		        }
		 	  });
		 	   $('.is_ok').bind('click',function(){
		        if($(this).is(':checked')){
		            $(this).parent().siblings('.soon').children('.rule-son').prop('checked',false);
		        }else{
		            $(this).parent().siblings('.soon').children('.rule-son').prop('checked',false);
		        }
		 	  });

		 	  $('.rule-son').bind('click',function(){
		        var checkLenth = $(this).parent().siblings('.soon').children('input[name="rules[]"]:checked').length;
		        if(checkLenth==3){
		        	$(this).parent().siblings('.soon').children('.rule-parent').prop('checked',true);
		        }else{
		        	$(this).parent().siblings('.soon').children('.rule-parent').prop('checked',false);
		        }
		        console.log(checkLenth);
		        if(!$(this).is(':checked') && checkLenth == 0){
		            $(this).parent().siblings('.parent-list').children('.rule-parent').prop('checked',false);
		        }else{
		        	
		        	 $(this).parent().siblings('.soon').children('.is_ok').prop('checked',false);
		        }
		    }); 
		 	  	
			$(".js-category-add").validate({
				rules: {
				 	remarks : {
		                required    : true,
		            },
		        
		            
					
				},
				messages: {
					remarks: {
						required: "备注不能为空"
					}
					
				},
				submitHandler: function () {
					$.post("/wallet/{{$action}}",$('.js-category-add').serialize(), function (msg) {
						if (msg.status == 1) {
							layer.confirm(msg.info, {
								btn: ['确定']
							}, function(){
								@if($action == 'lock_unlock')
									window.location.href="{{asset('wallet/wallet_list')}}";
								@else
									window.location.href="{{asset('wallet/wallet_list')}}";
								@endif
							});
						} else {
							showMsg(msg.info);
						}
					}, 'json');
					return false;
				}
			});
		});
		/**
		 * layer提示
		 */
		function showMsg(msg){
			layer.alert(msg, {
				title: '提示',
				icon: 2,
			});
		}
	</script>
</body>
</html>